package com.gzsxy.esjy.config.service.impl;

import com.gzsxy.esjy.config.refresh.RefreshEvent;
import com.gzsxy.esjy.config.service.ConfigManagerService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 配置中心
 * @date 2021/12/23 15:26
 */
@Service
public class ConfigManagerServiceImpl implements ConfigManagerService {

    @Autowired
    private ApplicationContext applicationContext;

    /**
     * 全局刷新配置文件
     */
    private final static String GLOBAL ="global";

    /**
     * @description: 刷新配置文件
     * @param
     * @return
     */
    @Override
    public void refresh(String application) {
        //全局刷新
        if (StringUtils.isBlank(application) || GLOBAL.equals(application)){
            applicationContext.publishEvent(new RefreshEvent(GLOBAL));
        //定点刷新
        } else {
            applicationContext.publishEvent(new RefreshEvent(application));
        }

    }
}
